getmyData('advertisingData', advertisingData)
var benDiDang4 = getmyData('advertisingData')
if (benDiDang4 == null) {
    setmyData('advertisingData', advertisingData)
    benDiDang4 = getmyData('advertisingData')
}

// 添加内容
function showTableFour(data) {
    myTbodyFour.innerHTML = ""
    data.forEach(item => {
        myTbodyFour.innerHTML += `  <tr>
                                       <td class="myTbodyFour_md1"><input type="checkbox" onclick = 'singleIn(${JSON.stringify(item)})' class="columnInput"></td>
                                       <td class="myTbodyFour_md2">${item.adrcode}</td>
                                       <td class="myTbodyFour_md3">${item.adrname}</td>
                                       <td class="myTbodyFour_md4"><img src="${item.goodsImg}" alt=""></td>
                                       <td class="myTbodyFour_md5"><a href="#">${item.JumpAddress}<a/></td>
                                       <td class="myTbodyFour_md6">${item.adrPosition}</td>
                                       <td class="myTbodyFour_md7">${item.adrTime}</td>
                                       <td class="myTbodyFour_md8"><input class="switch-btn switch-btn-animbg" type="checkbox" checked></td>
                                       <td class="myTbodyFour_md9">
                                          <span onclick = 'singleLineBJ(${JSON.stringify(item)})'>编辑</span> 
                                          <i class="myTbodyFourZD"  onclick = 'singleLineZD(${JSON.stringify(item)})'>置顶</i>
                                          <i class="myTbodyFourQX" onclick = 'singleLineQX(${JSON.stringify(item)})'>取消置顶</i>
                                          <span onclick = 'singleLineDel(${JSON.stringify(item)})'>删除</span></td>
                                    </tr>
                            `
    });
}

let myPage4 = 1
let zxMaxPage
// 限制每页数据
function limitPage4(data, node) {
    let myPageUlPress = document.getElementsByClassName('myPageUlPress')
    for (let i = 0; i < myPageUlPress.length; i++) {
        myPageUlPress[i].style.backgroundColor = '#fff'
        myPageUlPress[i].style.color = '#555'

    }
    myPageUlPress[data - 1].style.backgroundColor = 'rgb(24,144,255)'
    myPageUlPress[data - 1].style.color = '#fff'


    // 当前页
    let goPage4 = (data - 1) * 6
    let stopPage4 = node.slice(goPage4, goPage4 + 6)
    showTableFour(stopPage4)
    myPage4 = data
}






// 动态输出页码
function GetPageNumber4(data) {
    let myPageUl4 = document.getElementById('myPageUl4')
    //共多少记录
    let gongDuoShao = `<li class="myPageUlToTal"> 共 <span class="myPageUlToTal_shuzi"> 0 </span> 条记录 第 <span class="myPageUlToTal_ji"> 1 </span> / <span class="myPageUlToTal_yigong"> 0 <span> 页 </li>`

    // 页码
    zxMaxPage = Math.ceil(data.length / 5)
    // 上一页
    let zpre = `<li class="myPageUlPress_shang iconfont icon-xiangzuo" onclick=" shangPage() "></li>`
    let zstr = ''
    // 页码数循环添加页码
    for (let i = 1; i <= zxMaxPage; i++) {
        zstr += `<li class="myPageUlPress"   data-num_two='${i}'>${i}</li>`
    }

    let yeMtiaoZ = `<span class="myPageUlPress_tz">跳转至 <input class="myPageUlPress_shuru" type="text"> 页 <button onclick="myPageUlPress_ymtz()"> 确认 </button></span>`

    // 字符串拼接  下一页
    zstr = gongDuoShao + zpre + zstr + `<li class="myPageUlPress_xia iconfont icon-xiangyou1" onclick=" xiaPage()"></li>` + yeMtiaoZ
    myPageUl4.innerHTML = zstr
}
GetPageNumber4(benDiDang4)
limitPage4(myPage4, benDiDang4)


// 点击页码跳转 用这个方法点击置顶后就无效了
//     let myPageUlPress = document.getElementsByClassName('myPageUlPress')
//     for (let i = 0; i < myPageUlPress.length; i++) {
//         myPageUlPress[i].addEventListener('click', function () {
//             limitPage4(i + 1)
//             dangqianyeM()
//         })
//     }
// }

//  点击页码跳转
$('#myPageUl4').on('click', '.myPageUlPress', function () {
    myPage4 = $(this).attr('data-num_two')
    limitPage4(myPage4, benDiDang4)
    dangqianyeM()
})



// 上一页
function shangPage() {
    if (myPage4 != 1) {
        myPage4--
        limitPage4(myPage4, benDiDang4)
    }
    dangqianyeM()
}

// 下一页
function xiaPage() {
    if (myPage4 < zxMaxPage) {
        myPage4++
        limitPage4(myPage4, benDiDang4)
    }
    dangqianyeM()
}

// 渲染多少条记录
function talRecords(data) {
    $('.myPageUlToTal_shuzi').html(data.length)
}
talRecords(benDiDang4)

// 当前页码
function dangqianyeM() {
    $('.myPageUlToTal_ji').html(myPage4)
}
dangqianyeM()

// 一共多少页
function yigongDsy() {
    $('.myPageUlToTal_yigong').html(zxMaxPage + '页')
}
yigongDsy()


// 单行删除
function singleLineDel(data) {
    for (let i = 0; i < benDiDang4.length; i++) {
        if (data.adrcode == benDiDang4[i].adrcode) {
            benDiDang4.splice(i, 1)
            break;
        }
    }
    setmyData('advertisingData', advertisingData)
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 当前页
    talRecords(benDiDang4)
    // 重新渲染tbody
    showTableFour(benDiDang4)
    // 重新渲染每页数据
    limitPage4(myPage4, benDiDang4)
}

// 跳转页面
function myPageUlPress_ymtz() {
    myPage4 = $('.myPageUlPress_shuru').val()
    limitPage4(myPage4, benDiDang4)
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 共多少页
    talRecords(benDiDang4)
    // 当前页
    dangqianyeM()

}


// 置顶
let dqY
let ooo = []
let qishi = 0
function singleLineZD(data) {
    let myTbodyFourZD = document.getElementsByClassName('myTbodyFourZD')
    let myTbodyFourQX = document.getElementsByClassName('myTbodyFourQX')
    for (let i = 0; i < benDiDang4.length; i++) {
        if (data.adrcode == benDiDang4[i].adrcode) {
            dqY = i
            ooo = benDiDang4[i]
            console.log(ooo);
            benDiDang4.splice(i, 1)
            benDiDang4.unshift(ooo)
            break;
        }
    }
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // // 当前页
    // talRecords()
    // 重新渲染tbody
    showTableFour(benDiDang4)
    // 重新渲染每页数据
    limitPage4(myPage4, benDiDang4)

    for (let i = 0; i < benDiDang4.length; i++) {
        if (data.adrcode == benDiDang4[i].adrcode) {
            myTbodyFourZD[i].style.display = 'none'
            myTbodyFourQX[i].style.display = 'block'
            break;
        }
    }
}

// 取消置顶
function singleLineQX(data) {
    for (let i = 0; i < benDiDang4.length; i++) {
        if (data.adrcode == benDiDang4[i].adrcode) {
            benDiDang4.splice(qishi, 1, ...benDiDang4.splice(dqY, 1, benDiDang4[qishi]))
            break;
        }
    }
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 当前页
    // talRecords()
    // 重新渲染tbody
    showTableFour(benDiDang4)
    // 重新渲染每页数据
    limitPage4(myPage4, benDiDang4)
    // for (let i = 0; i < benDiDang4.length; i++) {
    //     if (data.adrcode == benDiDang4[i].adrcode) {
    //         myTbodyFourZD[i].style.display = 'block'
    //         myTbodyFourQX[i].style.display = 'none'
    //         break;
    //     }
    // }
}



// 编辑
function singleLineBJ(data) {
    $('.table_edit').css({
        display: 'block'
    })

    $('.whites').css({
        background: 'rgb(127,128,129,0.7)',
    })

    $('#columnList').css({
        zIndex: '-1',
    })

    $('#Advertising_list4').css({
        zIndex: '-1',

    })
    let table_edit1 = document.getElementById('table_edit1')
    let table_edit2 = document.getElementById('table_edit2')
    let table_edit3 = document.getElementById('table_edit3')
    let table_edit4 = document.getElementById('table_edit4')
    let table_edit6 = document.getElementById('table_edit6')
    let table_edit8 = document.getElementById('table_edit8')
    let table_edit3_2 = document.getElementById('table_edit3_2')

    table_edit1.value = data.adrname
    table_edit2.options.value = data.adrPosition
    // table_edit3.value = data.goodsImg
    table_edit4.value = data.JumpAddress
    table_edit6.value = data.adrTime
    table_edit8.value = data.adrcode
    table_edit3_2.src = data.goodsImg


}



// 编辑取消
function singleLineBJQX() {
    $('.table_edit').css({
        display: 'none'
    })

    $('.whites').css({
        background: 'rgb(240, 242, 245)',
    })

    $('#columnList').css({
        zIndex: '1',
    })

    $('#Advertising_list4').css({
        zIndex: '1',

    })

}
// 改变图片
let table_edit3_2 = document.getElementById('table_edit3_2')
function newfile(obj) {
    var reader = new FileReader();	// 实例化一个FileReader对象，用于读取文件
    reader.onload = function (evt) {
        table_edit3_2.src = evt.target.result;
    }
    reader.readAsDataURL(obj.files[0]);
}


// 编辑确定
function singleLineBJQD() {
    let table_edit1 = document.getElementById('table_edit1')
    let table_edit2 = document.getElementById('table_edit2')
    let table_edit3 = document.getElementById('table_edit3')
    let table_edit4 = document.getElementById('table_edit4')
    let table_edit6 = document.getElementById('table_edit6')
    let table_edit8 = document.getElementById('table_edit8')
    let table_edit3_2 = document.getElementById('table_edit3_2')
    for (let i = 0; i < benDiDang4.length; i++) {
        if (benDiDang4[i].adrcode == table_edit8.value) {
            benDiDang4[i].adrname = table_edit1.value
            benDiDang4[i].JumpAddress = table_edit4.value
            benDiDang4[i].adrTime = table_edit6.value
            benDiDang4[i].goodsImg = table_edit3_2.src
            // 获取当前选中索引
            let index = table_edit2.selectedIndex
            // 获取当前选中的文本值
            let setext = table_edit2.options[index].text
            benDiDang4[i].adrPosition = setext
            break;
        }
    }
    singleLineBJQX()
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 当前页
    talRecords(benDiDang4)
    // 重新渲染tbody
    showTableFour(benDiDang4)
    // 重新渲染每页数据
    limitPage4(myPage4, benDiDang4)
    setmyData('advertisingData', advertisingData)
}

// 新增
function newAdvertising() {
    $('.table_xinzen').css({
        display: 'block'
    })

    $('.whites').css({
        background: 'rgb(127,128,129,0.7)',
    })

    $('#columnList').css({
        zIndex: '-1',
    })

    $('#Advertising_list4').css({
        zIndex: '-1',

    })
}

// 新增取消
function singXinZenBJQX() {
    $('.table_xinzen').css({
        display: 'none'
    })

    $('.whites').css({
        background: 'rgb(240, 242, 245)',
    })

    $('#columnList').css({
        zIndex: '1',
    })

    $('#Advertising_list4').css({
        zIndex: '1',

    })
}


// 新填图片
let table_xinzen3_2 = document.getElementById('table_xinzen3_2')
function newfile(obj) {
    var readerXz = new FileReader();	// 实例化一个FileReader对象，用于读取文件
    readerXz.onload = function (evt) {
        table_xinzen3_2.src = evt.target.result;
    }
    readerXz.readAsDataURL(obj.files[0]);
}

// 新增确认
function singXinZenBJQD() {
    let table_xinzen1 = $('#table_xinzen1').val()
    let table_xinzen2 = document.getElementById('table_xinzen2')
    let table_xinzen3 = document.getElementById('table_xinzen3')
    let table_xinzen4 = document.getElementById('table_xinzen4').value
    let table_xinzen6 = document.getElementById('table_xinzen6').value
    let table_xinzen3_2 = document.getElementById('table_xinzen3_2')


    // 获取当前选中索引
    let index = table_xinzen2.selectedIndex
    // 获取当前选中的文本值
    let setext = table_xinzen2.options[index].text

    let niHaoYa = new XinTianJia(table_xinzen1, setext, table_xinzen3_2.src, table_xinzen4, table_xinzen6)

    function XinTianJia(adrname, adrPosition, goodsImg, JumpAddress, adrTime) {
        // 标题1
        this.adrname = adrname
        // 下拉2
        this.adrPosition = adrPosition
        // 图片3
        this.goodsImg = goodsImg
        // 网址4
        this.JumpAddress = JumpAddress
        // 时间
        this.adrTime = adrTime
    }
    console.log(niHaoYa);
    benDiDang4.push(niHaoYa)

    singXinZenBJQX()
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 当前页
    talRecords(benDiDang4)
    // 重新渲染tbody
    showTableFour(benDiDang4)
    // 重新渲染每页数据
    limitPage4(myPage4, benDiDang4)
    setmyData('advertisingData', advertisingData)
}



// 选中删除

var XiaB
function singleIn(data) {
    for (let i = 0; i < benDiDang4.length; i++) {
        if (data.adrcode == benDiDang4[i].adrcode) {
            XiaB = i
            $('.columnInput:checked').each(function () {
                benDiDang4.splice(XiaB, 1)
            })
        }
    }
    setmyData('advertisingData', advertisingData)
}

// 点击删除
function newAdverDel() {
    $('#checkShanc').css({
        display: 'block',

    })

    $('.whites').css({
        background: 'rgb(127,128,129,0.7)',
    })

    $('#columnList').css({
        zIndex: '-1',
    })

    $('#Advertising_list4').css({
        zIndex: '-1',

    })

}
// 删除取消
function deleteSelectedCancel() {
    $('#checkShanc').css({
        display: 'none',
    })

    $('.whites').css({
        background: 'rgb(240, 242, 245)',
    })

    $('#columnList').css({
        zIndex: '1',
    })

    $('#Advertising_list4').css({
        zIndex: '1',

    })

}

// 删除确定
function deleteSelectedJx() {
    setmyData('advertisingData', advertisingData)
    singXinZenBJQX()
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 当前页
    talRecords(benDiDang4)
    // 重新渲染tbody
    showTableFour(benDiDang4)
    // 重新渲染每页数据
    limitPage4(myPage4, benDiDang4)
    deleteSelectedCancel()
}


// 上线
function AdvertisingSX() {
    console.log(1);
}


// 查询
function columnListZX() {
    let columnList_select = document.getElementById('columnList_select')
    let benDiXSZ = []
    // 获取当前选中索引
    let index = columnList_select.selectedIndex
    // 获取当前选中的文本值
    let setext = columnList_select.options[index].text

    for (let i = 0; i < benDiDang4.length; i++) {
     /*    if ($('#columnList_ss').val()) {
            alert('请输入正确值')
            $('#columnList_ss').val("")
            break
        } else  */if ($('#columnList_ss').val() == benDiDang4[i].adrname || setext == benDiDang4[i].adrPosition) {
            benDiXSZ.push(benDiDang4[i])
            setmyData('advertisingData', advertisingData)
            // 渲染页码
            GetPageNumber4(benDiXSZ)
            limitPage4(myPage4, benDiXSZ)
            // 渲染tbody
            showTableFour(benDiXSZ)
            singXinZenBJQX()
            // 文字共多少页码
            yigongDsy()
            // 当前页
            dangqianyeM()
            // 渲染一共多少记录
            talRecords(benDiXSZ)
            // }
        }
    }
}


// 查询重置
function columnListZC() {
    setmyData('advertisingData', advertisingData)
    $('#columnList_ss').val("")
    // 渲染tbody
    showTableFour(benDiDang4)
    singXinZenBJQX()
    // 多少页码
    GetPageNumber4(benDiDang4)
    // 文字共多少页码
    yigongDsy()
    // 当前页
    dangqianyeM()
    // 渲染一共多少记录
    talRecords(benDiDang4)
    limitPage4(myPage4, benDiDang4)
}


